﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using AutoShutdownDotNet.Models;

namespace AutoShutdownDotNet
{
    public partial class PasswordForm : Form
    {
        public PasswordForm()
        {
            InitializeComponent();
        }

        public string Password
        {
            get { return txtPassword.Text; }
            set { txtPassword.Text = value; }
        }

        private void btnUnlock_Click(object sender, EventArgs e)
        {
            Setting setting = Setting.GetDefault();
            if(setting != null)
            {
                if (MD5Coder.Encode(Password) == setting.Password)
                {
                    DialogResult = DialogResult.OK;
                    Close();
                }
                else
                {
                    MessageBox.Show("The Password you entered is not valid.", "Password", MessageBoxButtons.OK,
                                    MessageBoxIcon.Error);
                    txtPassword.SelectAll();
                    txtPassword.Focus();
                }
            }
            else
            {
                DialogResult = DialogResult.OK;
                Close();
            }
        }
    }
}
